﻿<%@page contentType="text/html; charset=utf-8" language="java"%>
<%@page import="java.util.*"%>

<%@page import="com.easidea.tim.entity.saleorder.SaleOrderItem"%>
<%@page import="com.easidea.tim.entity.saleorder.SaleOrder"%>
<%@page import="com.easidea.tim.service.saleorder.SaleOrderService"%>
<%@page import="com.easidea.tim.service.saleorder.SaleOrderItemService"%>
<%@page import="org.springframework.web.context.WebApplicationContext"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="java.text.DecimalFormat"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<%
	String id = request.getParameter("id").toString();
	
	String meter = "";
	String productname = "";
	String productcolor = "";

	double moneyTotal = 0; 
	double meterTotal = 0;
	String meterArray [] = null;
	SaleOrderItemService saleOrderItemService = new SaleOrderItemService();
	SaleOrderService saleOrderService = new SaleOrderService();
	DecimalFormat df = new DecimalFormat("###.000");
	DecimalFormat dfone = new DecimalFormat("###.0");
	
	WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServletContext());
	List saleOrderlist = ((SaleOrderService)wac.getBean("saleOrderService")).GetSaleOrderListByid(new Integer(id).longValue());
	SaleOrder saleOrder = (SaleOrder)saleOrderlist.get(0);
	//SaleOrder saleOrder = saleOrderService.get(id);
	//List itemList = saleOrderItemDao.getItemsByOrderId(new Integer(id).longValue());
	List itemList = ((SaleOrderItemService)wac.getBean("saleOrderItemService")).getItemsByOrderId(new Integer(id).longValue());


	String customer = saleOrder.getCustomer().getName();
	String address = saleOrder.getReAddress();
	String phone = saleOrder.getCustomer().getContactorMobile()+";" + saleOrder.getCustomer().getBizTel1();
	String code = saleOrder.getFlowNo();
	String memo = saleOrder.getMemo();
		String date = "";
	if(saleOrder.getStatus()>2){
		date=saleOrder.getModifyTime().toLocaleString();
	}
	String type="";
	if(saleOrder.getOrderType().equals("2")||saleOrder.getOrderType().equals("3")){
		type ="退";
	}
 %>
<head>
    <title>可视化设计套打</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    
     <OBJECT ID="jatoolsPrinter" CLASSID="CLSID:B43D3361-D975-4BE2-87FE-057188254255"
 license="MWUwMDFlNTE1ZTAyNWE2YjEyNTI1YzVmNzk0YjBjNTg1ZDVmNWYxYTVmNTA0NjVmNWY1Yzc5NGExYjU4NWQ1NTVkMDI1YjU3NGM0MTU4NWM1ZDE5NDQ1MTU3" codebase="http://192.168.70.7/wz-web/print/jatoolsPrinter.cab#version=5,5,0,0"></OBJECT>
    
    <style>
	.title { 
	   font-family : Arial,Vernada,Tahoma, sans-serif;
	   font-size: 30px;
	   color : #00008B;
	   background-color : White; text-decoration:underline
	}
	.normal{
		font-family : Arial,Vernada, Tahoma, Helvetica, sans-serif;
		font-size: 14px;
		color: #444444;
		text-decoration: none;
		line-height: 180%;        
	}
	
	#page1 DIV {
		position:absolute;
	}
	
	.f1,.f2,.f3,.f4,.f5,.f6,.f7,.f8{top:80;left:2;}
	
	.customer{top:92;left:115}
	.address{top:92;left:347}
	.phone{top:92;left:600}
	.metertotal{top:305;left:560}
	.moneytotal{top:305;left:630}
	.code{top:58;left:585}
	.memo{top:305;left:115}
	.date{top:23;left:510}
	<%
		
		int top = 110;
		int col = 0;
		String colid="";
		for(int i=0;i<itemList.size();i++){
			col = col +1;
			top = 138 + (col-1)*27;
			SaleOrderItem orderItem = (SaleOrderItem)itemList.get(i);
			meterTotal = Double.valueOf(orderItem.getMeterNum()) + meterTotal;
			moneyTotal = (Double.valueOf(orderItem.getMeterNum()) * orderItem.getMoneyNum()) + moneyTotal;

			
			if(col==1){
				colid = "a";
			}else if(col == 2){
				colid = "b";
			}else if(col == 3){
				colid = "c";
			}else if(col == 4){
				colid = "d";
			}else if(col == 5){
				colid = "e";
			}else if(col == 6){
				colid = "f";
			}	
			
			if(i < 6){
	%>
		.my-<%=colid%>0{top:<%=top%>;left:80}
		.my-<%=colid%>1{top:<%=top%>;left:150}
		.my-<%=colid%>2{top:<%=top%>;left:200}
		.my-<%=colid%>3{top:<%=top%>;left:250}
		.my-<%=colid%>4{top:<%=top%>;left:330}
	<%
	}
	%>	
		<%
			if(i > 5){
				if(i ==6){
				col=1;
				}
			
			top = 138 + (i-6)*27;
				if(col==1){
					colid = "a";
				}else if(col == 2){
					colid = "b";
				}else if(col == 3){
					colid = "c";
				}else if(col == 4){
					colid = "d";
				}else if(col == 5){
					colid = "e";
				}else if(col == 6){
				colid = "f";
			}	
		%>
			.my-<%=colid%>5{top:<%=top%>;left:400}
			.my-<%=colid%>6{top:<%=top%>;left:480}
			.my-<%=colid%>7{top:<%=top%>;left:520}
			.my-<%=colid%>8{top:<%=top%>;left:565}
			.my-<%=colid%>9{top:<%=top%>;left:630}
		<%
			
			}
		%>
		
	<%
		}	
	%>
	</style>
			  <script language="JavaScript">
	function doPrint(isPreview)  {
	
	    myDoc = {
	        settings: {
	            topMargin:50,leftMargin:100,bottomMargin:50,rightMargin:100,
	            orientation: 1},//打印纸张方向，纵向为1横向为2
			
	        documents: document,
	        //dragDesigner:true,
	        marginIgnored:true,
	        dragDesigner:{viewSource:false},
	        loadPrintSettings:true,
	        savePrintSettings:true, 
	        settingsID: 'saleorderreturn<%=id%>',
	        enableScreenOnlyClass:true,
	        copyrights:'杰创软件拥有版权   www.jatools.com'
	    };
	
	    if(isPreview){
				jatoolsPrinter.printPreview(myDoc); //预览
			}else{
				jatoolsPrinter.print(myDoc,true); // 打印弹出打印机的选择框  
			}
	}
	window.onload = function() { doPrint(true); } //直接打印预览				
	</script>
</head>
<body>&nbsp;&nbsp; &nbsp;
<body >
<p class="title"> <input type="button" value="打印预览" onClick="doPrint();"></p>

<div style='padding:0;background-color:#808080;width:210mm;height:105mm;overflow:auto;'>

	<div id="page1" style='padding-left:20px,padding-top:18px;width:210mm;height:105mm;position:relative'>
		<img src="../image/jianyang2.jpg" style='position:absolute;width:100%;height:100%;'/>
		<div id='customer' draggable='true' class='customer my-customer' style='position:absolute;font-size:13;' ><%=customer %></div>
		<div id='address' draggable='true' class='address my-address' style='position:absolute;font-size:13;' ><%=address %></div>
		<div id='phone' draggable='true' class='phone my-phone' style='position:absolute;font-size:13;' ><%=phone %></div>
		<div id='metertotal' draggable='true' class='metertotal my-metertotal' style='position:absolute;font-size:14;font-family:Arial' ><%=dfone.format(meterTotal) %></div>
		<div id='moneyTotal' draggable='true' class='moneyTotal my-moneyTotal' style='position:absolute;font-size:14;font-family:Arial' ><%=Double.parseDouble(df.format(moneyTotal)) %></div>
		<div id='code' draggable='true' class='code my-code' style='position:absolute;font-size:16;' ><%=type + code %></div>
		<div id='memo' draggable='true' class='memo my-memo' style='position:absolute;font-size: 13;' ><%=memo %></div>
		<div id='date' draggable='true' class='date my-date' style='position:absolute;font-size:16;' >出库日期：<%=date %></div>
		<%
		
		top = 150;
		col = 0;
		colid="";
		for(int i=0;i<itemList.size();i++){
			col = col +1;
			SaleOrderItem orderItem = (SaleOrderItem)itemList.get(i);
			productname = orderItem.getProductName();
			productcolor = orderItem.getProductColor()+"#";
			
			if(col==1){
				colid = "a";
			}else if(col == 2){
				colid = "b";
			}else if(col == 3){
				colid = "c";
			}else if(col == 4){
				colid = "d";
			}else if(col == 5){
				colid = "e";
			}else if(col == 6){
				colid = "f";
			}	
			
			if(i < 6){
	%>
		<div id='<%= colid%>0' draggable='true' class='<%= colid%>0 my-<%= colid%>0' style='position:absolute;font-family:Arial;font-size:14' ><%=productname%></div>
		<div id='<%= colid%>1' draggable='true' class='<%= colid%>1 my-<%= colid%>1' style='position:absolute;font-family:Arial;font-size:14' ><%=productcolor%></div>
		<div id='<%= colid%>2' draggable='true' class='<%= colid%>2 my-<%= colid%>2' style='position:absolute;font-family:Arial' ><%= orderItem.getMoneyNum()%></div>
		<div id='<%= colid%>3' draggable='true' class='<%= colid%>3 my-<%= colid%>3' style='position:absolute;font-family:Arial' ><%= Double.parseDouble(dfone.format(orderItem.getTotalMeter()))%></div>
		<div id='<%= colid%>4' draggable='true' class='<%= colid%>4 my-<%= colid%>4' style='position:absolute;font-family:Arial' ><%=Double.parseDouble(df.format(orderItem.getMoneyNum()*orderItem.getTotalMeter()))%></div>
		
		<%
		}
		 %>
		
		<%
			if(i > 5){
			if(i==6){
				col=1;
			}
				if(col==1){
					colid = "a";
				}else if(col == 2){
					colid = "b";
				}else if(col == 3){
					colid = "c";
				}else if(col == 4){
					colid = "d";
				}else if(col == 5){
					colid = "e";
				}else if(col == 6){
				colid = "f";
			}
				
		%>
		<div id='<%= colid%>5' draggable='true' class='<%= colid%>5 my-<%= colid%>5' style='position:absolute;font-family:Arial;font-size:14' ><%=productname%></div>
		<div id='<%= colid%>6' draggable='true' class='<%= colid%>6 my-<%= colid%>6' style='position:absolute;font-family:Arial;font-size:14' ><%=productcolor%></div>
		<div id='<%= colid%>7' draggable='true' class='<%= colid%>7 my-<%= colid%>7' style='position:absolute;font-family:Arial' ><%= orderItem.getMoneyNum()%></div>
		<div id='<%= colid%>8' draggable='true' class='<%= colid%>8 my-<%= colid%>8' style='position:absolute;font-family:Arial' ><%= Double.parseDouble(dfone.format(orderItem.getTotalMeter()))%></div>
		<div id='<%= colid%>9' draggable='true' class='<%= colid%>9 my-<%= colid%>9' style='position:absolute;font-family:Arial' ><%= Double.parseDouble(df.format(orderItem.getMoneyNum()*orderItem.getTotalMeter()))%></div>
		<%
			}
		}		
	%>

	</div>
</div>

</body>
</html>
